home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / ntunzip2.zip / UNZIP.H < prev    next >
C/C++ Source or Header  |  1994-02-10  |  61KB  |  1,773 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   unzip.h
  4.  
  5.   This header file is used by all of the UnZip source files.  Its contents
  6.   are divided into seven more-or-less separate sections:  predefined macros,
  7.   OS-dependent includes, (mostly) OS-independent defines, typedefs, function 
  8.   prototypes (or "forward declarations," in the case of non-ANSI compilers),
  9.   macros, and global-variable declarations.
  10.  
  11.   ---------------------------------------------------------------------------*/
  12.  
  13.  
  14.  
  15. #ifndef __unzip_h   /* prevent multiple inclusions */
  16. #define __unzip_h
  17.  
  18. /*****************************************/
  19. /*  Predefined, Machine-specific Macros  */
  20. /*****************************************/
  21.  
  22. #if defined(__GO32__) && defined(unix)   /* MS-DOS extender:  NOT Unix */
  23. #  undef unix
  24. #endif
  25.  
  26. #if defined(unix) || defined(M_XENIX) || defined(COHERENT) || defined(__hpux)
  27. #  ifndef UNIX
  28. #    define UNIX
  29. #  endif
  30. #endif /* unix || M_XENIX || COHERENT || __hpux */
  31. #if defined(__convexc__) || defined(MINIX)
  32. #  ifndef UNIX
  33. #    define UNIX
  34. #  endif
  35. #endif /* __convexc__ || MINIX */
  36.  
  37. #ifdef __COMPILER_KCC__
  38. #  include <c-env.h>
  39. #  ifdef SYS_T20
  40. #    define TOPS20
  41. #  endif
  42. #endif /* __COMPILER_KCC__ */
  43.  
  44. /* define MSDOS for Turbo C (unless OS/2) and Power C as well as Microsoft C */
  45. #ifdef __POWERC
  46. #  define __TURBOC__
  47. #  define MSDOS
  48. #endif /* __POWERC */
  49. #if defined(__MSDOS__) && (!defined(MSDOS))   /* just to make sure */
  50. #  define MSDOS
  51. #endif
  52.  
  53. #if defined(linux) && (!defined(LINUX))
  54. #  define LINUX
  55. #endif
  56.  
  57. /* use prototypes and ANSI libraries if __STDC__, or Microsoft or Borland C, or
  58.  * Silicon Graphics, or Convex?, or IBM C Set/2, or GNU gcc/emx, or Watcom C,
  59.  * or Macintosh, or Windows NT, or Sequent, or Atari.
  60.  */
  61. #if defined(__STDC__) || defined(MSDOS) || defined(sgi)
  62. #  ifndef PROTO
  63. #    define PROTO
  64. #  endif
  65. #  define MODERN
  66. #endif
  67. #if defined(__IBMC__) || defined(__EMX__) || defined(__WATCOMC__)
  68. #  ifndef PROTO
  69. #    define PROTO
  70. #  endif
  71. #  define MODERN
  72. #endif
  73. #if defined(THINK_C) || defined(MPW) || defined(WIN32) || defined(_SEQUENT_)
  74. #  ifndef PROTO
  75. #    define PROTO
  76. #  endif
  77. #  define MODERN
  78. #endif
  79. #if defined(ATARI_ST) || defined(__BORLANDC__)  /* || defined(__convexc__) */
  80. #  ifndef PROTO
  81. #    define PROTO
  82. #  endif
  83. #  define MODERN
  84. #endif
  85.  
  86. /* turn off prototypes if requested */
  87. #if defined(NOPROTO) && defined(PROTO)
  88. #  undef PROTO
  89. #endif
  90.  
  91. /* used to remove arguments in function prototypes for non-ANSI C */
  92. #ifdef PROTO
  93. #  define OF(a) a
  94. #else /* !PROTO */
  95. #  define OF(a) ()
  96. #endif /* ?PROTO */
  97.  
  98. /* bad or (occasionally?) missing stddef.h: */
  99. #if defined(M_XENIX) || defined(DNIX)
  100. #  define NO_STDDEF_H
  101. #endif
  102.  
  103. #if (defined(__NetBSD__) && !defined(__386BSD__))
  104. #  define __386BSD__
  105. #endif
  106.  
  107. #if 0  /* GRR 931003:  BOGUS!  Screwed-up systems can define this explicitly */
  108. /* cannot depend on MODERN for presence of stdlib.h */
  109. #if defined(__GNUC__)
  110. #  if (!defined(__EMX__) && !defined(__386BSD__) && !defined(LINUX))
  111. #    define NO_STDLIB_H
  112. #  endif
  113. #endif /* __GNUC__ */
  114. #endif /* 0 */
  115.  
  116. #if defined(apollo)          /* defines __STDC__ */
  117. #    define NO_STDLIB_H
  118. #endif /* apollo */
  119.  
  120. #ifdef DNIX
  121. #  define SYSV
  122. #  define SHORT_NAMES         /* 14-char limitation on path components */
  123. /* #  define FILENAME_MAX  14 */
  124. #  define FILENAME_MAX  NAME_MAX    /* GRR:  experiment */
  125. #endif
  126.  
  127. #if (defined(__SYSTEM_FIVE) || defined(M_SYSV) || defined(M_SYS5))
  128. #  ifndef SYSV
  129. #    define SYSV
  130. #  endif /* !SYSV */
  131. #endif /* __SYSTEM_FIVE || M_SYSV || M_SYS5 */
  132.  
  133. #if (defined(SYSV) || defined(CRAY) || defined(LINUX))
  134. #  ifndef TERMIO
  135. #    define TERMIO
  136. #  endif /* !TERMIO */
  137. #endif /* SYSV || CRAY || LINUX */
  138.  
  139. #if (defined(ultrix) || defined(bsd4_2) || defined(sun) || defined(pyr))
  140. #  if (!defined(BSD) && !defined(SYSV))
  141. #    define BSD
  142. #  endif
  143. #endif /* ultrix || bsd4_2 || sun || pyr */
  144. #if defined(__convexc__) || defined(__386BSD__)
  145. #  if (!defined(BSD) && !defined(SYSV))
  146. #    define BSD
  147. #  endif
  148. #endif /* __convexc__ || __386BSD__ */
  149.  
  150. #ifdef pyr  /* Pyramid */
  151. #  ifdef BSD
  152. #    define pyr_bsd
  153. #  endif
  154. #  define ZMEM            /* should ZMEM only be for BSD universe...? */
  155. #  define DECLARE_ERRNO   /*  (AT&T memcpy was claimed to be very slow) */
  156. #endif /* pyr */
  157.  
  158. #if (defined(CRAY) && defined(ZMEM))
  159. #  undef ZMEM
  160. #endif
  161.  
  162. /* stat() bug for Borland, Watcom, VAX C (also GNU?), and Atari ST MiNT on
  163.  * TOS filesystems:  returns 0 for wildcards!  (returns 0xffffffff on Minix
  164.  * filesystem or U: drive under Atari MiNT) */
  165. #if (defined(__TURBOC__) || defined(__WATCOMC__) || defined(VMS))
  166. #  define WILD_STAT_BUG
  167. #endif
  168. #if (defined(__MINT__))
  169. #  define WILD_STAT_BUG
  170. #endif
  171.  
  172. #ifdef WILD_STAT_BUG
  173. #  define SSTAT(path,pbuf) (iswild(path) || stat(path,pbuf))
  174. #else
  175. #  define SSTAT stat
  176. #endif
  177.  
  178. #define STRNICMP zstrnicmp
  179.  
  180. #if 0  /* internal version renamed to zstrnicmp and used for all systems now */
  181. /* SCO Unix, dnix, Interactive SysV (all SysV?):  no strnicmp or strncasecmp.
  182.  * Also Sun 386i, VMS (just VAX C?), djgpp 1.10 and earlier, Coherent. */
  183. #if (defined(SYSV) || defined(sun386) || defined(VMS) || defined(__GO32__))
  184. #  define NO_STRNICMP
  185. #endif
  186. #if (defined(COHERENT))
  187. #  define NO_STRNICMP
  188. #endif
  189. #ifndef NO_STRNICMP
  190. #  if (!defined(MODERN) || defined(NeXT) || defined(CRAY) || defined(LINUX))
  191. #    define strnicmp strncasecmp
  192. #  endif
  193. #  if (defined(__386BSD__) || defined(__bsdi__))
  194. #    define strnicmp strncasecmp
  195. #  endif
  196. #endif
  197. #endif /* 0 */
  198.  
  199.  
  200.  
  201.  
  202.  
  203. /***************************/
  204. /*  OS-Dependent Includes  */
  205. /***************************/
  206.  
  207. #ifndef MINIX            /* Minix needs it after all the other includes (?) */
  208. #  include <stdio.h>
  209. #endif
  210. #include <ctype.h>       /* skip for VMS, to use tolower() function? */
  211. #include <errno.h>       /* used in mapname() */
  212. #include <string.h>      /* GRR:  EXPERIMENTAL! */
  213. #ifdef MODERN
  214. #  include <limits.h>    /* GRR:  EXPERIMENTAL!  (can be deleted) */
  215. #endif
  216.  
  217. #if 0    /* GRR:  MORE EXPERIMENTING (moved to OS sections) */
  218. #ifdef VMS
  219. #  include <types.h>     /* (placed up here instead of in VMS section below */
  220. #  include <stat.h>      /* because types.h is used in some other headers) */
  221. #else /* !VMS */
  222. #    if (!defined(THINK_C) && !defined(MPW) && !defined(ATARI_ST) && !defined(AZTEC_C))
  223. #      include <sys/types.h>         /* off_t, time_t, dev_t, ... */
  224. #      include <sys/stat.h>
  225. #    endif /* !THINK_C && !MPW && !ATARI_ST && !AZTEC_C */
  226. #endif /* ?VMS */
  227. #endif
  228.  
  229. #ifdef EFT
  230. #  define LONGINT off_t  /* Amdahl UTS nonsense ("extended file types") */
  231. #else
  232. #  define LONGINT long
  233. #endif
  234.  
  235. #ifdef MODERN
  236. #  ifndef NO_STDDEF_H
  237. #    include <stddef.h>
  238. #  endif
  239. #  ifndef NO_STDLIB_H
  240. #    include <stdlib.h>    /* standard library prototypes, malloc(), etc. */
  241. #  endif
  242.    typedef size_t extent;
  243.    typedef void voidp;
  244. /* #  include <string.h> */      /* defines strcpy, strcmp, memcpy, etc. */
  245. #else /* !MODERN */
  246. /*    char *strchr(), *strrchr();  */
  247.    LONGINT lseek();
  248.    char *malloc();
  249.    typedef unsigned int extent;
  250.    typedef char voidp;
  251. #  define void int
  252. #endif /* ?MODERN */
  253.  
  254. /* this include must be down here for SysV.4, for some reason... */
  255. #include <signal.h>      /* used in unzip.c, file_io.c */
  256.  
  257. /*---------------------------------------------------------------------------
  258.     Amiga section:
  259.   ---------------------------------------------------------------------------*/
  260.  
  261. #ifdef AMIGA
  262. #  include "amiga/amiga.h"
  263. #  ifndef AZTEC_C
  264. #    include <sys/types.h>      /* off_t, time_t, dev_t, ... */
  265. #    include <sys/stat.h>
  266. #  endif
  267. #  include <fcntl.h>            /* O_BINARY for open() w/o CR/LF translation */
  268. #  define DATE_FORMAT   DF_MDY
  269. #  define lenEOL        1
  270. #  define PutNativeEOL  *q++ = native(LF);
  271. /* #  define USE_FWRITE   if write() returns 16-bit int */
  272. #endif
  273.  
  274. /*---------------------------------------------------------------------------
  275.     Atari ST section:
  276.   ---------------------------------------------------------------------------*/
  277.  
  278. #if (defined(ATARI_ST) || defined(__MINT__))    /* comments by [cjh] */
  279. #  ifdef __TURBOC__
  280. #    include <ext.h>   /* stat() */
  281. #    include <tos.h>   /* OS-specific functions (Fdup) */
  282. #  endif
  283. #  include <time.h>
  284. #  ifndef __MINT__
  285. #    define dup     Fdup
  286. #    define mkdir   Dcreate
  287. #    define DIR_END '\\'
  288. #  else
  289. #    include <sys/types.h>     /* didn't we include this already? */
  290. #    include <sys/stat.h>
  291. #    include <fcntl.h>         /* O_BINARY */
  292. #    include <unistd.h>        /* dup proto & unix system calls live here */
  293. #    include <time.h>
  294. #    include <stdio.h>         /* didn't we include this already? */
  295. #    define dup dup
  296. #    define mkdir mkdir
  297. #    define DIR_END '/'        /* much sexier than DOS filenames... */
  298. #    define timezone _timezone /* oops */
  299. #    define DIRENT
  300. #    define SYMLINKS
  301. #    ifdef S_ISLNK             /* WARNING:  horrible kludge!!!! */
  302. #      undef S_ISLNK           /* MiNTlibs <= pl.41 have symlinks wrong! */
  303. #      define S_ISLNK(a) (((a) & 0xa000) == 0xa000)
  304. #    endif                     /* remove this when it's fixed! */
  305. #    ifdef SHORT_NAMES         /* library will truncate weird names on TOS fs */
  306. #      undef SHORT_NAMES
  307. #    endif
  308. #    ifndef ZMEM
  309. #      define ZMEM             /* we have bcopy, etc., ifndef __STRICT_ANSI__ */
  310. #    endif
  311. #  endif /* __MINT__ */
  312. #  ifndef S_IFMT
  313. #    define S_IFMT     (S_IFCHR | S_IFREG | S_IFDIR)
  314. #  endif
  315.  
  316. // change by lgk 2/10/94 to remove compiler warning for nt
  317. #ifndef WIN32
  318. #  define DATE_FORMAT  DF_MDY
  319. #endif
  320.  
  321. #  ifndef lenEOL
  322. #    define lenEOL 2           /* DOS convention; MiNT doesn't really care */
  323. #  endif
  324. #  ifndef PutNativeEOL
  325. #    define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  326. #  endif
  327. #endif
  328.  
  329. /*---------------------------------------------------------------------------
  330.     Mac section:
  331.   ---------------------------------------------------------------------------*/
  332.  
  333. #ifdef THINK_C
  334. #  define MACOS
  335. #  ifndef __STDC__            /* if Think C hasn't defined __STDC__ ... */
  336. #    define __STDC__ 1        /*   make sure it's defined: it needs it */
  337. #  else /* __STDC__ defined */
  338. #    if !__STDC__             /* sometimes __STDC__ is defined as 0; */
  339. #      undef __STDC__         /*   it needs to be 1 or required header */
  340. #      define __STDC__ 1      /*   files are not properly included. */
  341. #    endif /* !__STDC__ */
  342. #  endif /* ?defined(__STDC__) */
  343. #  define CREATOR       'KAHL'
  344. #endif /* THINK_C */
  345.  
  346. #ifdef MPW
  347. #  define MACOS
  348. #  include <Errors.h>
  349. #  include <Files.h>
  350. #  include <Memory.h>
  351. #  include <Quickdraw.h>
  352. #  include <ToolUtils.h>
  353. #  ifdef fileno
  354. #    undef fileno
  355. #  endif
  356. #  ifdef MCH_MACINTOSH
  357. #    define CREATOR     'Manx'
  358. #  else
  359. #    define CREATOR     'MPS '
  360. #  endif
  361. #endif /* MPW */
  362.  
  363. #ifdef MACOS
  364. #  include <fcntl.h>            /* O_BINARY for open() w/o CR/LF translation */
  365. #  define fileno(x)     ((x) == stdout ? 1 : (short)(x))
  366. #  define open(x,y)     macopen((x), (y), gnVRefNum, glDirID)
  367. #  define fopen(x,y)    macfopen((x), (y), gnVRefNum, glDirID)
  368. #  define close         macclose
  369. #  define fclose(x)     macclose(fileno((x)))
  370. #  define read          macread
  371. #  define write         macwrite
  372. #  define lseek         maclseek
  373. #  define creat(x,y)    maccreat((x), gnVRefNum, glDirID, gostCreator, gostType)
  374. #  define stat(x,y)     macstat((x), (y), gnVRefNum, glDirID)
  375. #  define dup
  376. #  ifndef MCH_MACINTOSH
  377. #    define NO_STRNICMP
  378. #  endif
  379. #  define DIR_END ':'
  380. #  define DATE_FORMAT   DF_MDY
  381. #  define lenEOL        1
  382. #  define PutNativeEOL  *q++ = native(CR);
  383. #  define MALLOC_WORK
  384.  
  385. #  ifdef THINK_C
  386. #    define fgets       wfgets
  387. #    define fflush(f)
  388. #    define fprintf     wfprintf
  389. #    define fputs(s,f)  wfprintf((f), "%s", (s))
  390. #    define printf      wprintf
  391. #    ifdef putc
  392. #      undef putc
  393. #    endif
  394. #    define putc(c,f)   wfprintf((f), "%c", (c))
  395. #    define getenv      macgetenv
  396. #  endif
  397.  
  398. #  ifndef isascii
  399. #    define isascii(c)  ((unsigned char)(c) <= 0x3F)
  400. #  endif
  401.  
  402. #  include "macstat.h"
  403. #  include "macdir.h"
  404.  
  405. #  ifdef CR
  406. #    undef  CR
  407. #  endif
  408.  
  409. typedef struct _ZipExtraHdr {
  410.     unsigned short header;    /*    2 bytes */
  411.     unsigned short data;      /*    2 bytes */
  412. } ZIP_EXTRA_HEADER;
  413.  
  414. typedef struct _MacInfoMin {
  415.     unsigned short header;    /*    2 bytes */
  416.     unsigned short data;      /*    2 bytes */
  417.     unsigned long signature;  /*    4 bytes */
  418.     FInfo finfo;              /*   16 bytes */
  419.     unsigned long lCrDat;     /*    4 bytes */
  420.     unsigned long lMdDat;     /*    4 bytes */
  421.     unsigned long flags ;     /*    4 bytes */
  422.     unsigned long lDirID;     /*    4 bytes */
  423.                               /*------------*/
  424. } MACINFOMIN;                 /* = 40 bytes for size of data */
  425.  
  426. typedef struct _MacInfo {
  427.     unsigned short header;    /*    2 bytes */
  428.     unsigned short data;      /*    2 bytes */
  429.     unsigned long signature;  /*    4 bytes */
  430.     FInfo finfo;              /*   16 bytes */
  431.     unsigned long lCrDat;     /*    4 bytes */
  432.     unsigned long lMdDat;     /*    4 bytes */
  433.     unsigned long flags ;     /*    4 bytes */
  434.     unsigned long lDirID;     /*    4 bytes */
  435.     char rguchVolName[28];    /*   28 bytes */
  436.                               /*------------*/
  437. } MACINFO;                    /* = 68 bytes for size of data */
  438. #endif /* MACOS */
  439.  
  440. /*---------------------------------------------------------------------------
  441.     MS-DOS and OS/2 section:
  442.   ---------------------------------------------------------------------------*/
  443.  
  444. #ifdef MSDOS
  445. #  include <dos.h>           /* for REGS macro (TC) or _dos_setftime (MSC) */
  446. #  ifdef __TURBOC__          /* includes Power C */
  447. #    include <sys/timeb.h>   /* for structure ftime */
  448. #    ifndef __BORLANDC__     /* there appears to be a bug (?) in Borland's */
  449. #      include <mem.h>       /*  MEM.H related to __STDC__ and far poin-   */
  450. #    endif                   /*  ters. (dpk)  [mem.h included for memcpy]  */
  451. #  endif
  452. #endif /* MSDOS */
  453.  
  454. #ifdef __IBMC__
  455. #  define S_IFMT 0xF000
  456. #  define timezone _timezone
  457. #  define PIPE_ERROR (errno == EERRSET || errno == EOS2ERR)
  458. #endif
  459.  
  460. #ifdef __WATCOMC__
  461. #  define __32BIT__
  462. #  undef far
  463. #  define far
  464. #  undef near
  465. #  define near
  466. #  define PIPE_ERROR (errno == -1)
  467. #endif
  468.  
  469. #ifdef __EMX__
  470. #  ifndef __32BIT__
  471. #    define __32BIT__
  472. #  endif
  473. #  define far
  474. #endif
  475.  
  476. #ifdef __GO32__              /* note: MS-DOS compiler, not OS/2 */
  477. #  ifndef __32BIT__
  478. #    define __32BIT__
  479. #  endif
  480. #  include <sys/timeb.h>     /* for structure ftime */
  481.    int setmode(int, int);    /* not in djgpp's include files */
  482. #endif
  483.  
  484. #if defined(_MSC_VER) && (!defined(MSC))
  485. #  define MSC                /* for old versions, MSC must be set explicitly */
  486. #endif
  487.  
  488. #if 0  /* GRR 930907:  MSC 5.1 does declare errno but doesn't define _MSC_VER */
  489. #ifdef MSC
  490. #  ifndef _MSC_VER           /* new with 5.1 or 6.0 ... */
  491. #    define DECLARE_ERRNO    /* not declared in errno.h in 5.0 or earlier? */
  492. #  endif
  493. #endif
  494. #endif /* 0 */
  495.  
  496. #if defined(MSDOS) || defined(OS2)
  497. #  include <sys/types.h>      /* off_t, time_t, dev_t, ... */
  498. #  include <sys/stat.h>
  499. #  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  500. #  include <time.h>           /* localtime() */
  501. #  include <fcntl.h>          /* O_BINARY for open() w/o CR/LF translation */
  502. #  define DIR_END '\\'
  503. #  if (defined(M_I86CM) || defined(M_I86LM))
  504. #    define MED_MEM
  505. #  endif
  506. #  if (defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__))
  507. #    define MED_MEM
  508. #  endif
  509. #  ifndef __32BIT__
  510. #    ifndef MED_MEM
  511. #      define SMALL_MEM
  512. #    endif
  513. #    define USE_FWRITE        /* write() cannot write more than 32767 bytes */
  514. #  endif
  515.  
  516. // change by lgk 2/10/94 to remove compiler warning for nt
  517. #ifndef WIN32
  518. #  define DATE_FORMAT  dateformat()
  519. #endif
  520.  
  521. #  define lenEOL        2
  522. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  523. #endif
  524.  
  525. #ifdef OS2                    /* defined for all OS/2 compilers */
  526. #  ifdef MSDOS
  527. #    undef MSDOS
  528. #  endif
  529. #  ifdef isupper
  530. #    undef isupper
  531. #  endif
  532. #  ifdef tolower
  533. #    undef tolower
  534. #  endif
  535. #  define isupper(x)   IsUpperNLS((unsigned char)(x))
  536. #  define tolower(x)   ToLowerNLS((unsigned char)(x))
  537. #endif
  538.  
  539. #if defined(MSWIN) && defined(FILE_IO_C)
  540. #  include "wizunzip.h"
  541. #endif
  542.  
  543. /*---------------------------------------------------------------------------
  544.     MTS section (piggybacks UNIX, I think):
  545.   ---------------------------------------------------------------------------*/
  546.  
  547. #ifdef MTS
  548. #  include <sys/types.h>    /* off_t, time_t, dev_t, ... */
  549. #  include <sys/stat.h>
  550. #  include <sys/file.h>     /* MTS uses this instead of fcntl.h */
  551. #  include <timeb.h>
  552. #  include <time.h>
  553. #  include <unix.h>         /* some important non-ANSI routines */
  554. #  define mkdir(s,n) (-1)   /* no "make directory" capability */
  555. #  define EBCDIC            /* set EBCDIC conversion on */
  556. #  define NO_STRNICMP       /* unzip's is as good the one in MTS */
  557. #  define USE_FWRITE
  558. #  define close_outfile()  fclose(outfile)   /* can't set time on files */
  559. #  define umask(n)            /* Don't have umask() on MTS */
  560. #  define FOPWT         "w"   /* Open file for writing in TEXT mode */
  561. #  define DATE_FORMAT   DF_MDY
  562. #  define lenEOL        1
  563. #  define PutNativeEOL  *q++ = native(LF);
  564. #endif
  565.  
  566. /*---------------------------------------------------------------------------
  567.     NT section:
  568.   ---------------------------------------------------------------------------*/
  569.  
  570. #ifdef WIN32  /* NT */
  571. #  include <sys/types.h>        /* off_t, time_t, dev_t, ... */
  572. #  include <sys/stat.h>
  573. #  include <io.h>               /* read(), open(), etc. */
  574. #  include <time.h>
  575. #  include <memory.h>
  576. #  include <direct.h>           /* mkdir() */
  577. #  include <fcntl.h>
  578. #  if defined(FILE_IO_C)
  579. #    include <conio.h>
  580. #    include <sys\types.h>
  581. #    include <sys\utime.h>
  582. #    include <windows.h>
  583. #  endif
  584. #  define DATE_FORMAT   DF_MDY
  585. #  define lenEOL        2
  586. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  587. #  define NT
  588. #endif
  589.  
  590. /*---------------------------------------------------------------------------
  591.     TOPS-20 section:
  592.   ---------------------------------------------------------------------------*/
  593.  
  594. #ifdef TOPS20
  595. #  include <sys/types.h>        /* off_t, time_t, dev_t, ... */
  596. #  include <sys/stat.h>
  597. #  include <sys/param.h>
  598. #  include <sys/time.h>
  599. #  include <sys/timeb.h>
  600. /* #  include <utime.h>            GRR: not used, I suspect... */
  601. #  include <sys/file.h>
  602. #  include <timex.h>
  603. #  include <monsym.h>           /* get amazing monsym() macro */
  604.    extern int open(), close(), read();
  605.    extern int stat(), unlink(), jsys(), fcntl();
  606.    extern long lseek(), dup(), creat();
  607. #  define strchr    index       /* GRR: necessary? */
  608. #  define strrchr   rindex
  609. #  define REALLY_SHORT_SYMS
  610. #  define NO_MKDIR
  611. #  define DIR_BEG  '<'
  612. #  define DIR_END  '>'
  613. #  define DIR_EXT  ".directory"
  614. #  define DATE_FORMAT  DF_MDY
  615. #endif /* TOPS20 */
  616.  
  617. /*---------------------------------------------------------------------------
  618.     Unix section:
  619.   ---------------------------------------------------------------------------*/
  620.  
  621. #ifdef UNIX
  622. #  include <sys/types.h>       /* off_t, time_t, dev_t, ... */
  623. #  include <sys/stat.h>
  624.  
  625. #  ifndef COHERENT
  626. #    include <fcntl.h>         /* O_BINARY for open() w/o CR/LF translation */
  627. #  else /* COHERENT */
  628. #    ifdef _I386
  629. #      include <fcntl.h>       /* Coherent 4.0.x, Mark Williams C */
  630. #    else
  631. #      include <sys/fcntl.h>   /* Coherent 3.10, Mark Williams C */
  632. #    endif
  633. #    define SHORT_SYMS
  634. #    ifndef __COHERENT__       /* Coherent 4.2 has tzset() */
  635. #      define tzset  settz
  636. #    endif
  637. #  endif /* ?COHERENT */
  638.  
  639. #  ifndef NO_PARAM_H
  640. #    ifdef NGROUPS_MAX
  641. #      undef NGROUPS_MAX       /* SCO bug:  defined again in <sys/param.h> */
  642. #    endif
  643. #    ifdef BSD
  644. #      define TEMP_BSD         /* may be defined again in <sys/param.h> */
  645. #      undef BSD
  646. #    endif
  647. #    include <sys/param.h>     /* conflict with <sys/types.h>, some systems? */
  648. #    if defined(TEMP_BSD) && !defined(BSD)
  649. #      define BSD
  650. #      undef TEMP_BSD
  651. #    endif
  652. #  endif /* !NO_PARAM_H */
  653.  
  654. #  ifdef BSD
  655. #    include <sys/time.h>
  656. #    include <sys/timeb.h>
  657. #    ifdef _AIX
  658. #      include <time.h>
  659. #    endif
  660. #  else
  661. #    include <time.h>
  662.      struct tm *gmtime(), *localtime();
  663. #  endif
  664.  
  665. #  if defined(__386BSD__) || defined(LINUX) || (defined(SYSV)&&defined(MODERN))
  666. #    include <unistd.h>        /* this includes utime.h, at least on SGIs */
  667. #  endif
  668.  
  669. #  if defined(__386BSD__) ||defined(_POSIX_SOURCE) ||defined(sgi)||defined(_AIX)
  670. #    include <utime.h>   /* NeXT, at least, does NOT define utimbuf in here */
  671. #  else
  672.      struct utimbuf {
  673.          time_t actime;        /* new access time */
  674.          time_t modtime;       /* new modification time */
  675.      };
  676. #  endif /* ?(__386BSD__ || _POSIX_SOURCE || sgi || _AIX) */
  677.  
  678. #  if (defined(V7) || defined(pyr_bsd))
  679. #    define strchr   index
  680. #    define strrchr  rindex
  681. #  endif
  682. #  ifdef V7
  683. #    define O_RDONLY 0
  684. #    define O_WRONLY 1
  685. #    define O_RDWR   2
  686. #  endif
  687.  
  688. #  ifdef MINIX
  689. #    include <stdio.h>
  690. #  endif
  691. #  define DATE_FORMAT   DF_MDY
  692. #  define lenEOL        1
  693. #  define PutNativeEOL  *q++ = native(LF);
  694. #endif /* UNIX */
  695.  
  696. /*---------------------------------------------------------------------------
  697.     VMS section:
  698.   ---------------------------------------------------------------------------*/
  699.  
  700. #ifdef VMS
  701. #  include <types.h>              /* GRR:  experimenting... */
  702. #  include <stat.h>
  703. #  include <time.h>               /* the usual non-BSD time functions */
  704. #  include <file.h>               /* same things as fcntl.h has */
  705. #  include <rms.h>
  706. #  define _MAX_PATH NAM$C_MAXRSS  /* to define FILNAMSIZ below */
  707. #  define RETURN    return_VMS    /* VMS interprets return codes incorrectly */
  708. #  define DIR_BEG  '['
  709. #  define DIR_END  ']'
  710. #  define DIR_EXT  ".dir"
  711. #  define DATE_FORMAT  DF_MDY
  712. #  define lenEOL        1
  713. #  define PutNativeEOL  *q++ = native(LF);
  714. #endif /* VMS */
  715.  
  716. /*---------------------------------------------------------------------------
  717.     X68000/Human68k section:
  718.   ---------------------------------------------------------------------------*/
  719.  
  720. #ifdef __human68k__    /* DO NOT DEFINE DOS_OS2 HERE!  If Human68k is so much */
  721. #  include <time.h>    /*  like MS-DOS and/or OS/2, create DOS_HUM_OS2 macro! */
  722. #  include <fcntl.h>
  723. #  include <io.h>
  724. #  include <conio.h>
  725. #  include <jctype.h>
  726. #  include <sys/stat.h>
  727. #  define DATE_FORMAT  DF_YMD    /* Japanese standard */
  728.       /* GRR:  these EOL macros are guesses */
  729. #  define lenEOL        2
  730. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  731. #endif
  732.  
  733.  
  734.  
  735.  
  736.  
  737. /*************/
  738. /*  Defines  */
  739. /*************/
  740.  
  741. #define UNZIP
  742. #define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
  743. #define VMS_VERSION       42   /* if OS-needed-to-extract is VMS:  can do */
  744.  
  745. #if defined(MSDOS) || defined(NT) || defined(OS2)
  746. #  define DOS_NT_OS2
  747. #endif
  748.  
  749. #if defined(MSDOS) || defined(OS2)
  750. #  define DOS_OS2
  751. #endif
  752.  
  753. #if defined(MSDOS) || defined(OS2) || defined(ATARI_ST)
  754. #  define DOS_OS2_TOS
  755. #endif
  756.  
  757. #if defined(MSDOS) || defined(ATARI_ST)
  758. #  define DOS_TOS
  759. #endif
  760.  
  761. #if defined(MSDOS) || defined(TOPS20) || defined(VMS)
  762. #  define DOS_T20_VMS
  763. #endif
  764.  
  765. #if defined(TOPS20) || defined(VMS)
  766. #  define T20_VMS
  767. #endif
  768.  
  769. /* GRR:  NT defines MSDOS?? */
  770. #if (!defined(MSDOS) && !defined(__IBMC__)) || defined(NT)
  771. #  define near
  772. #  define far
  773. #endif
  774. #if defined(__GO32__) || defined(__EMX__)
  775. #  define near
  776. #  define far
  777. #endif
  778.  
  779. /* clean up with a couple of defaults */
  780. #ifndef DIR_END
  781. #  define DIR_END '/'       /* last char before program name (or filename) */
  782. #endif
  783. #ifndef RETURN
  784. #  define RETURN  return    /* only used in main() */
  785. #endif
  786.  
  787. #define DIR_BLKSIZ  64      /* number of directory entries per block
  788.                              *  (should fit in 4096 bytes, usually) */
  789. #ifndef WSIZE
  790. #  define WSIZE     0x8000  /* window size--must be a power of two, and */
  791. #endif                      /*  at least 32K for zip's deflate method */
  792.  
  793. #ifndef INBUFSIZ
  794. #  define INBUFSIZ  0x0800  /* 2K:  works for MS-DOS small model */
  795. #endif
  796.  
  797. /* Logic for case of small memory, length of EOL > 1:  if OUTBUFSIZ == 2048,
  798.  * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
  799.  * and transbuf 1040 bytes.  Have room for 32 extra EOL chars; 1008/32 == 31.5
  800.  * chars/line, smaller than estimated 35-70 characters per line for C source
  801.  * and normal text.  Hence difference is sufficient for most "average" files.
  802.  * (Argument scales for larger OUTBUFSIZ.)
  803.  */
  804. #ifdef SMALL_MEM          /* i.e., 16-bit OS's:  MS-DOS, OS/2 1.x, etc. */
  805. #  define NO_ZIPINFO      /* GRR:  true until move all strings to far memory */
  806. #  define OUTBUFSIZ INBUFSIZ
  807. #  if (lenEOL == 1)
  808. #    define RAWBUFSIZ (OUTBUFSIZ>>1)
  809. #  else
  810. #    define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
  811. #  endif
  812. #  define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
  813. #else
  814. #  ifdef MED_MEM
  815. #    define OUTBUFSIZ 0xFF80     /* can't malloc arrays of 0xFFE8 or more */
  816. #    define TRANSBUFSIZ 0xFF80
  817. #  else
  818. #    define OUTBUFSIZ (lenEOL*WSIZE)  /* more efficient text conversion */
  819. #    define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
  820. #  endif
  821. #  define RAWBUFSIZ OUTBUFSIZ
  822. #endif /* ?SMALL_MEM */
  823.  
  824. #if (defined(SFX) && !defined(NO_ZIPINFO))
  825. #  define NO_ZIPINFO
  826. #endif
  827.  
  828. #ifndef O_BINARY
  829. #  define O_BINARY  0
  830. #endif
  831.  
  832. #ifndef PIPE_ERROR
  833. #  define PIPE_ERROR (errno == EPIPE)
  834. #endif
  835.  
  836. /* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
  837. #ifdef VMS
  838. #  define FOPR  "r","ctx=stm"
  839. #  define FOPM  "r+","ctx=stm","rfm=fix","mrs=512"
  840. #  define FOPW  "w","ctx=stm","rfm=fix","mrs=512"
  841. #else /* !VMS */
  842. #  if defined(MODERN) || defined(AMIGA)
  843. #    define FOPR "rb"
  844. #    define FOPM "r+b"
  845. #    ifdef TOPS20          /* TOPS-20 MODERN?  You kidding? */
  846. #      define FOPW "w8"
  847. #    else
  848. #      define FOPW "wb"
  849. #    endif
  850. #  else /* !MODERN */
  851. #    define FOPR "r"
  852. #    define FOPM "r+"
  853. #    define FOPW "w"
  854. #  endif /* ?MODERN */
  855. #endif /* VMS */
  856.  
  857. /*
  858.  * If <limits.h> exists on most systems, should include that, since it may
  859.  * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
  860.  * _POSIX_PATH_MAX.
  861.  */
  862. #ifdef DOS_OS2_TOS
  863. #  include <limits.h>
  864. #endif
  865.  
  866. #ifndef PATH_MAX
  867. #  ifdef MAXPATHLEN
  868. #    define PATH_MAX      MAXPATHLEN    /* in <sys/param.h> on some systems */
  869. #  else
  870. #    ifdef _MAX_PATH
  871. #      define PATH_MAX    _MAX_PATH
  872. #    else
  873. #      if FILENAME_MAX > 255
  874. #        define PATH_MAX  FILENAME_MAX  /* used like PATH_MAX on some systems */
  875. #      else
  876. #        define PATH_MAX  1024
  877. #      endif
  878. #    endif /* ?_MAX_PATH */
  879. #  endif /* ?MAXPATHLEN */
  880. #endif /* !PATH_MAX */
  881.  
  882. #define FILNAMSIZ  (PATH_MAX+1)
  883.  
  884. #ifdef SHORT_SYMS                   /* Mark Williams C, ...? */
  885. #  define extract_or_test_files     xtr_or_tst_files
  886. #  define extract_or_test_member    xtr_or_tst_member
  887. #endif
  888.  
  889. #ifdef REALLY_SHORT_SYMS            /* TOPS-20 linker:  first 6 chars */
  890. #  define process_cdir_file_hdr     XXpcdfh
  891. #  define process_local_file_hdr    XXplfh
  892. #  define extract_or_test_files     XXxotf  /* necessary? */
  893. #  define extract_or_test_member    XXxotm  /* necessary? */
  894. #  define check_for_newer           XXcfn
  895. #  define overwrite_all             XXoa
  896. #  define process_all_files         XXpaf
  897. #  define extra_field               XXef
  898. #  define explode_lit8              XXel8
  899. #  define explode_lit4              XXel4
  900. #  define explode_nolit8            XXnl8
  901. #  define explode_nolit4            XXnl4
  902. #  define cpdist8                   XXcpdist8
  903. #  define inflate_codes             XXic
  904. #  define inflate_stored            XXis
  905. #  define inflate_fixed             XXif
  906. #  define inflate_dynamic           XXid
  907. #  define inflate_block             XXib
  908. #  define maxcodemax                XXmax
  909. #endif
  910.  
  911. #define ZSUFX             ".zip"
  912. #define CENTRAL_HDR_SIG   "\113\001\002"   /* the infamous "PK" signature */
  913. #define LOCAL_HDR_SIG     "\113\003\004"   /*  bytes, sans "P" (so unzip */
  914. #define END_CENTRAL_SIG   "\113\005\006"   /*  executable not mistaken for */
  915. #define EXTD_LOCAL_SIG    "\113\007\010"   /*  zipfile itself) */
  916.  
  917. #define SKIP              0    /* choice of activities for do_string() */
  918. #define DISPLAY           1
  919. #define FILENAME          2
  920. #define EXTRA_FIELD       3
  921.  
  922. #define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
  923. #define EXISTS_AND_OLDER  0
  924. #define EXISTS_AND_NEWER  1
  925.  
  926. #define ROOT              0    /* checkdir() extract-to path:  called once */
  927. #define INIT              1    /* allocate buildpath:  called once per member */
  928. #define APPEND_DIR        2    /* append a dir comp.:  many times per member */
  929. #define APPEND_NAME       3    /* append actual filename:  once per member */
  930. #define GETPATH           4    /* retrieve the complete path and free it */
  931. #define END               5    /* free root path prior to exiting program */
  932.  
  933. /* version_made_by codes (central dir):  make sure these */
  934. /*  are not defined on their respective systems!! */
  935. #define FS_FAT_           0    /* filesystem used by MS-DOS, OS/2, NT */
  936. #define AMIGA_            1
  937. #define VMS_              2
  938. #define UNIX_             3
  939. #define VM_CMS_           4
  940. #define ATARI_            5    /* what if it's a minix filesystem? [cjh] */
  941. #define FS_HPFS_          6    /* filesystem used by OS/2, NT */
  942. #define MAC_              7
  943. #define Z_SYSTEM_         8
  944. #define CPM_              9
  945. #define TOPS20_           10
  946. #define FS_NTFS_          11   /* filesystem used by Windows NT */
  947. /* #define QDOS_          12?  */
  948. #define NUM_HOSTS         12   /* index of last system + 1 */
  949.  
  950. #define STORED            0    /* compression methods */
  951. #define SHRUNK            1
  952. #define REDUCED1          2
  953. #define REDUCED2          3
  954. #define REDUCED3          4
  955. #define REDUCED4          5
  956. #define IMPLODED          6
  957. #define TOKENIZED         7
  958. #define DEFLATED          8
  959. #define NUM_METHODS       9    /* index of last method + 1 */
  960. /* don't forget to update list_files() appropriately if NUM_METHODS changes */
  961.  
  962. #define PK_OK             0    /* no error */
  963. #define PK_COOL           0    /* no error */
  964. #define PK_GNARLY         0    /* no error */
  965. #define PK_WARN           1    /* warning error */
  966. #define PK_ERR            2    /* error in zipfile */
  967. #define PK_BADERR         3    /* severe error in zipfile */
  968. #define PK_MEM            4    /* insufficient memory */
  969. #define PK_MEM2           5    /* insufficient memory */
  970. #define PK_MEM3           6    /* insufficient memory */
  971. #define PK_MEM4           7    /* insufficient memory */
  972. #define PK_MEM5           8    /* insufficient memory */
  973. #define PK_NOZIP          9    /* zipfile not found */
  974. #define PK_PARAM          10   /* bad or illegal parameters specified */
  975. #define PK_FIND           11   /* no files found */
  976. #define PK_DISK           50   /* disk full */
  977. #define PK_EOF            51   /* unexpected EOF */
  978.  
  979. #define IZ_DIR            76   /* potential zipfile is a directory */
  980. #define IZ_CREATED_DIR    77   /* directory created: set time and permissions */
  981. #define IZ_VOL_LABEL      78   /* volume label, but can't set on hard disk */
  982.  
  983. #define DF_MDY            0    /* date format 10/26/91 (USA only) */
  984. #define DF_DMY            1    /* date format 26/10/91 (most of the world) */
  985. #define DF_YMD            2    /* date format 91/10/26 (a few countries) */
  986.  
  987. /*---------------------------------------------------------------------------
  988.     True sizes of the various headers, as defined by PKWARE--so it is not
  989.     likely that these will ever change.  But if they do, make sure both these
  990.     defines AND the typedefs below get updated accordingly.
  991.   ---------------------------------------------------------------------------*/
  992. #define LREC_SIZE     26    /* lengths of local file headers, central */
  993. #define CREC_SIZE     42    /*  directory headers, and the end-of-    */
  994. #define ECREC_SIZE    18    /*  central-dir record, respectively      */
  995.  
  996. #define MAX_BITS      13                 /* used in unshrink() */
  997. #define HSIZE         (1 << MAX_BITS)    /* size of global work area */
  998.  
  999. #define LF      10    /* '\n' on ASCII machines; must be 10 due to EBCDIC */
  1000. #define CR      13    /* '\r' on ASCII machines; must be 13 due to EBCDIC */
  1001. #define CTRLZ   26    /* DOS & OS/2 EOF marker (used in file_io.c, vms.c) */
  1002.  
  1003. #ifdef EBCDIC
  1004. #  define native(c)   ebcdic[(c)]
  1005. #  define NATIVE      "EBCDIC"
  1006. #endif
  1007.  
  1008. #ifdef MPW
  1009. #  define FFLUSH(f)   putc('\n',f)
  1010. #else
  1011. #  define FFLUSH      fflush
  1012. #endif
  1013.  
  1014. #ifdef ZMEM     /* GRR:  THIS IS AN EXPERIMENT... (seems to work) */
  1015. #  undef ZMEM
  1016. #  define memcpy(dest,src,len)   bcopy(src,dest,len)
  1017. #  define memzero                bzero
  1018. #else
  1019. #  define memzero(dest,len)      memset(dest,0,len)
  1020. #endif
  1021.  
  1022. #ifdef VMS
  1023. #  define ENV_UNZIP     "UNZIP_OPTS"      /* name of environment variable */
  1024. #  define ENV_ZIPINFO   "ZIPINFO_OPTS"
  1025. #else /* !VMS */
  1026. #  define ENV_UNZIP     "UNZIP"
  1027. #  define ENV_ZIPINFO   "ZIPINFO"
  1028. #endif /* ?VMS */
  1029.  
  1030. #if !defined(QQ) && !defined(NOQQ)
  1031. #  define QQ
  1032. #endif
  1033.  
  1034. #ifdef QQ                         /* Newtware version:  no file */
  1035. #  define QCOND     (!qflag)      /*  comments with -vq or -vqq */
  1036. #else                             /* Bill Davidsen version:  no way to */
  1037. #  define QCOND     (which_hdr)   /*  kill file comments when listing */
  1038. #endif
  1039.  
  1040. #ifdef OLD_QQ
  1041. #  define QCOND2    (qflag < 2)
  1042. #else
  1043. #  define QCOND2    (!qflag)
  1044. #endif
  1045.  
  1046. #ifndef TRUE
  1047. #  define TRUE      1   /* sort of obvious */
  1048. #endif
  1049. #ifndef FALSE
  1050. #  define FALSE     0
  1051. #endif
  1052.  
  1053. #ifndef SEEK_SET
  1054. #  define SEEK_SET  0
  1055. #  define SEEK_CUR  1
  1056. #  define SEEK_END  2
  1057. #endif
  1058.  
  1059. #if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
  1060. #  define SYMLINKS
  1061. #  ifndef S_ISLNK
  1062. #    define S_ISLNK(m)  (((m) & S_IFMT) == S_IFLNK)
  1063. #  endif
  1064. #endif /* UNIX && S_IFLNK && !MTS */
  1065.  
  1066. #ifndef S_ISDIR
  1067. #  define S_ISDIR(m)  (((m) & S_IFMT) == S_IFDIR)
  1068. #endif
  1069.  
  1070. #ifndef IS_VOLID
  1071. #  define IS_VOLID(m)  ((m) & 0x08)
  1072. #endif
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078. /**************/
  1079. /*  Typedefs  */
  1080. /**************/
  1081.  
  1082. typedef char              boolean;
  1083. typedef unsigned char     uch;  /* code assumes unsigned bytes; these type-  */
  1084. typedef unsigned short    ush;  /*  defs replace byte/UWORD/ULONG (which are */
  1085. typedef unsigned long     ulg;  /*  predefined on some systems) & match zip  */
  1086.  
  1087. typedef struct min_info {
  1088.     long offset;
  1089.     ulg compr_size;          /* compressed size (needed if extended header) */
  1090.     ulg crc;                 /* crc (needed if extended header) */
  1091.     int hostnum;
  1092.     unsigned file_attr;      /* local flavor, as used by creat(), chmod()... */
  1093.     unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing */
  1094.     unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
  1095.     unsigned textfile : 1;   /* file is text (according to zip) */
  1096.     unsigned textmode : 1;   /* file is to be extracted as text */
  1097.     unsigned lcflag : 1;     /* convert filename to lowercase */
  1098.     unsigned vollabel : 1;   /* "file" is an MS-DOS volume (disk) label */
  1099. } min_info;
  1100.  
  1101. typedef struct VMStimbuf {
  1102.     char *revdate;           /* (both correspond to Unix modtime/st_mtime) */
  1103.     char *credate;
  1104. } VMStimbuf;
  1105.  
  1106. /*---------------------------------------------------------------------------
  1107.     Zipfile work area declarations.
  1108.   ---------------------------------------------------------------------------*/
  1109.  
  1110. #ifdef MALLOC_WORK
  1111.    union work {
  1112.      struct {
  1113.        short *Prefix_of;            /* (8193 * sizeof(short)) */
  1114.        uch *Suffix_of;
  1115.        uch *Stack;
  1116.      } shrink;                      /* unshrink() */
  1117.      uch *Slide;                    /* explode(), inflate(), unreduce() */
  1118.    };
  1119.  
  1120. #else /* !MALLOC_WORK */
  1121.    union work {
  1122.      struct {
  1123. #ifdef HSIZE2    /* needed to avoid errors on some machines? */
  1124.        short Prefix_of[HSIZE + 2];  /* (8194 * sizeof(short)) */
  1125.        uch Suffix_of[HSIZE + 2];    /* also s-f length_nodes (smaller) */
  1126.        uch Stack[HSIZE + 2];        /* also s-f distance_nodes (smaller) */
  1127. #else /* !HSIZE2 */
  1128.        short Prefix_of[HSIZE];      /* (8192 * sizeof(short)) */
  1129.        uch Suffix_of[HSIZE];        /* also s-f length_nodes (smaller) */
  1130.        uch Stack[HSIZE];            /* also s-f distance_nodes (smaller) */
  1131. #endif /* ?HSIZE2 */
  1132.      } shrink;
  1133.      uch Slide[WSIZE];
  1134.    };
  1135. #endif /* ?MALLOC_WORK */
  1136.  
  1137. #define prefix_of   area.shrink.Prefix_of
  1138. #define suffix_of   area.shrink.Suffix_of
  1139. #define stack       area.shrink.Stack
  1140. #define slide       area.Slide
  1141.  
  1142. /*---------------------------------------------------------------------------
  1143.     Zipfile layout declarations.  If these headers ever change, make sure the
  1144.     xxREC_SIZE defines (above) change with them!
  1145.   ---------------------------------------------------------------------------*/
  1146.  
  1147.    typedef uch   local_byte_hdr[ LREC_SIZE ];
  1148. #      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  1149. #      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  1150. #      define L_GENERAL_PURPOSE_BIT_FLAG        2
  1151. #      define L_COMPRESSION_METHOD              4
  1152. #      define L_LAST_MOD_FILE_TIME              6
  1153. #      define L_LAST_MOD_FILE_DATE              8
  1154. #      define L_CRC32                           10
  1155. #      define L_COMPRESSED_SIZE                 14
  1156. #      define L_UNCOMPRESSED_SIZE               18
  1157. #      define L_FILENAME_LENGTH                 22
  1158. #      define L_EXTRA_FIELD_LENGTH              24
  1159.  
  1160.    typedef uch   cdir_byte_hdr[ CREC_SIZE ];
  1161. #      define C_VERSION_MADE_BY_0               0
  1162. #      define C_VERSION_MADE_BY_1               1
  1163. #      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  1164. #      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  1165. #      define C_GENERAL_PURPOSE_BIT_FLAG        4
  1166. #      define C_COMPRESSION_METHOD              6
  1167. #      define C_LAST_MOD_FILE_TIME              8
  1168. #      define C_LAST_MOD_FILE_DATE              10
  1169. #      define C_CRC32                           12
  1170. #      define C_COMPRESSED_SIZE                 16
  1171. #      define C_UNCOMPRESSED_SIZE               20
  1172. #      define C_FILENAME_LENGTH                 24
  1173. #      define C_EXTRA_FIELD_LENGTH              26
  1174. #      define C_FILE_COMMENT_LENGTH             28
  1175. #      define C_DISK_NUMBER_START               30
  1176. #      define C_INTERNAL_FILE_ATTRIBUTES        32
  1177. #      define C_EXTERNAL_FILE_ATTRIBUTES        34
  1178. #      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  1179.  
  1180.    typedef uch   ec_byte_rec[ ECREC_SIZE+4 ];
  1181. /*     define SIGNATURE                         0   space-holder only */
  1182. #      define NUMBER_THIS_DISK                  4
  1183. #      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  1184. #      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  1185. #      define TOTAL_ENTRIES_CENTRAL_DIR         10
  1186. #      define SIZE_CENTRAL_DIRECTORY            12
  1187. #      define OFFSET_START_CENTRAL_DIRECTORY    16
  1188. #      define ZIPFILE_COMMENT_LENGTH            20
  1189.  
  1190.  
  1191.    typedef struct local_file_header {                 /* LOCAL */
  1192.        uch version_needed_to_extract[2];
  1193.        ush general_purpose_bit_flag;
  1194.        ush compression_method;
  1195.        ush last_mod_file_time;
  1196.        ush last_mod_file_date;
  1197.        ulg crc32;
  1198.        ulg csize;
  1199.        ulg ucsize;
  1200.        ush filename_length;
  1201.        ush extra_field_length;
  1202.    } local_file_hdr;
  1203.  
  1204.    typedef struct central_directory_file_header {     /* CENTRAL */
  1205.        uch version_made_by[2];
  1206.        uch version_needed_to_extract[2];
  1207.        ush general_purpose_bit_flag;
  1208.        ush compression_method;
  1209.        ush last_mod_file_time;
  1210.        ush last_mod_file_date;
  1211.        ulg crc32;
  1212.        ulg csize;
  1213.        ulg ucsize;
  1214.        ush filename_length;
  1215.        ush extra_field_length;
  1216.        ush file_comment_length;
  1217.        ush disk_number_start;
  1218.        ush internal_file_attributes;
  1219.        ulg external_file_attributes;
  1220.        ulg relative_offset_local_header;
  1221.    } cdir_file_hdr;
  1222.  
  1223.    typedef struct end_central_dir_record {            /* END CENTRAL */
  1224.        ush number_this_disk;
  1225.        ush num_disk_with_start_central_dir;
  1226.        ush num_entries_centrl_dir_ths_disk;
  1227.        ush total_entries_central_dir;
  1228.        ulg size_central_directory;
  1229.        ulg offset_start_central_directory;
  1230.        ush zipfile_comment_length;
  1231.    } ecdir_rec;
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237. /*************************/
  1238. /*  Function Prototypes  */
  1239. /*************************/
  1240.  
  1241. #ifndef __
  1242. #  define __   OF
  1243. #endif
  1244.  
  1245. /*---------------------------------------------------------------------------
  1246.     Functions in unzip.c (main initialization/driver routines):
  1247.   ---------------------------------------------------------------------------*/
  1248.  
  1249. int    uz_opts                   __((int *pargc, char ***pargv));
  1250. int    usage                     __((int error));
  1251. int    process_zipfiles          __((void));
  1252. int    do_seekable               __((int lastchance));
  1253. int    uz_end_central            __((void));
  1254. int    process_cdir_file_hdr     __((void));
  1255. int    process_local_file_hdr    __((void));
  1256.  
  1257. /*---------------------------------------------------------------------------
  1258.     Functions in zipinfo.c (zipfile-listing routines):
  1259.   ---------------------------------------------------------------------------*/
  1260.  
  1261. int    zi_opts                   __((int *pargc, char ***pargv));
  1262. int    zi_end_central            __((void));
  1263. int    zipinfo                   __((void));
  1264. /* static int    zi_long         __((void)); */
  1265. /* static int    zi_short        __((void)); */
  1266. /* static char  *zi_time         __((ush *datez, ush *timez)); */
  1267. ulg    SizeOfEAs                 __((void *extra_field));  /* also in os2.c? */
  1268. int    list_files                __((void));
  1269. /* static int    ratio           __((ulg uc, ulg c)); */
  1270.  
  1271. /*---------------------------------------------------------------------------
  1272.     Functions in file_io.c:
  1273.   ---------------------------------------------------------------------------*/
  1274.  
  1275. int      open_input_file    __((void));
  1276. int      open_outfile       __((void));                        /* also vms.c */
  1277. int      readbuf            __((char *buf, register unsigned len));
  1278. int      FillBitBuffer      __((void));
  1279. int      readbyte           __((void));
  1280. #ifdef FUNZIP
  1281.    int   flush              __((ulg size));
  1282. #else
  1283.    int   flush              __((uch *buf, ulg size, int unshrink));
  1284. #endif
  1285. void     handler            __((int signal));
  1286. time_t   dos_to_unix_time   __((unsigned ddate, unsigned dtime));
  1287. int      check_for_newer    __((char *filename));       /* also os2.c, vms.c */
  1288. int      find_end_central_dir __((long searchlen));        /* find_ecrec */
  1289. int      get_cdir_file_hdr  __((void));                    /* get_cdir_ent */
  1290. int      do_string          __((unsigned int len, int option));
  1291. ush      makeword           __((uch *b));
  1292. ulg      makelong           __((uch *sig));
  1293. int      zstrnicmp __((register char *s1, register char *s2, register int n));
  1294.  
  1295. #ifdef ZMEM   /* MUST be ifdef'd because of conflicts with the standard def. */
  1296.    char *memset __((register char *, register char, register unsigned int));
  1297.    char *memcpy __((register char *, register char *, register unsigned int));
  1298. #endif
  1299.  
  1300. /*---------------------------------------------------------------------------
  1301.     Functions in extract.c:
  1302.   ---------------------------------------------------------------------------*/
  1303.  
  1304. int    extract_or_test_files     __((void));
  1305. /* static int   store_info               __((void)); */
  1306. /* static int   extract_or_test_member   __((void)); */
  1307. int    memextract                __((uch *, ulg, uch *, ulg));
  1308. int    FlushMemory               __((void));
  1309. int    ReadMemoryByte            __((ush *x));
  1310.  
  1311. /*---------------------------------------------------------------------------
  1312.     Decompression functions:
  1313.   ---------------------------------------------------------------------------*/
  1314.  
  1315. int    explode                   __((void));                    /* explode.c */
  1316. int    inflate                   __((void));                    /* inflate.c */
  1317. int    inflate_free              __((void));                    /* inflate.c */
  1318. void   unreduce                  __((void));                   /* unreduce.c */
  1319. /* static void  LoadFollowers    __((void));                    * unreduce.c */
  1320. int    unshrink                  __((void));                   /* unshrink.c */
  1321. /* static void  partial_clear    __((void));                    * unshrink.c */
  1322.  
  1323. /*---------------------------------------------------------------------------
  1324.     Human68K-only functions:
  1325.   ---------------------------------------------------------------------------*/
  1326.  
  1327. #ifdef __human68k__
  1328.    void     InitTwentyOne        __((void));
  1329. #endif
  1330.  
  1331. /*---------------------------------------------------------------------------
  1332.     Macintosh-only functions:
  1333.   ---------------------------------------------------------------------------*/
  1334.  
  1335. #ifdef MACOS
  1336.    int      macmkdir             __((char *, short, long));
  1337.    short    macopen              __((char *, short, short, long));
  1338.    FILE    *macfopen             __((char *, char *, short, long));
  1339.    short    maccreat             __((char *, short, long, OSType, OSType));
  1340.    short    macread              __((short, char *, unsigned));
  1341.    long     macwrite             __((short, char *, unsigned));
  1342.    short    macclose             __((short));
  1343.    long     maclseek             __((short, long, short));
  1344.    char    *wfgets               __((char *, int, FILE *));
  1345.    void     wfprintf             __((FILE *, char *, ...));
  1346.    void     wprintf              __((char *, ...));
  1347. #endif
  1348.  
  1349. /*---------------------------------------------------------------------------
  1350.     MSDOS-only functions:
  1351.   ---------------------------------------------------------------------------*/
  1352.  
  1353. #if (defined(__GO32__) || (defined(MSDOS) && defined(__EMX__)))
  1354.    void _dos_setftime(int, unsigned short, unsigned short);       /* msdos.c */
  1355.    void _dos_setfileattr(char *, int);                            /* msdos.c */
  1356.    unsigned _dos_creat(char *, unsigned, int *);                  /* msdos.c */
  1357.    void _dos_getdrive(unsigned *);                                /* msdos.c */
  1358.    unsigned _dos_close(int);                                      /* msdos.c */
  1359. #endif
  1360.  
  1361. /*---------------------------------------------------------------------------
  1362.     OS/2-only functions:
  1363.   ---------------------------------------------------------------------------*/
  1364.  
  1365. #ifdef OS2  /* GetFileTime conflicts with something in NT header files */
  1366.    int   GetCountryInfo   __((void));                               /* os2.c */
  1367.    long  GetFileTime      __((char *name));                         /* os2.c */
  1368.    void  SetPathInfo      __((char *path, ush moddate, ush modtime, int flags));
  1369.    int   IsEA             __((void *extra_field));                  /* os2.c */
  1370.    void  SetEAs           __((char *path, void *eablock));          /* os2.c */
  1371.    ulg   SizeOfEAs        __((void *extra_field));                  /* os2.c */
  1372. /* static int   IsFileNameValid __((char *name));                      os2.c */
  1373. /* static void  map2fat         __((char *pathcomp, char **pEndFAT));  os2.c */
  1374. /* static int   SetLongNameEA   __((char *name, char *longname));      os2.c */
  1375. /* static void  InitNLS         __((void));                            os2.c */
  1376.    int   IsUpperNLS       __((int nChr));                           /* os2.c */
  1377.    int   ToLowerNLS       __((int nChr));                           /* os2.c */
  1378.    void  DebugMalloc      __((void));                               /* os2.c */
  1379. #endif
  1380.  
  1381. /*---------------------------------------------------------------------------
  1382.     TOPS20-only functions:
  1383.   ---------------------------------------------------------------------------*/
  1384.  
  1385. #ifdef TOPS20
  1386.    int upper               __((char *s));                        /* tops20.c */
  1387.    int enquote             __((char *s));                        /* tops20.c */
  1388.    int dequote             __((char *s));                        /* tops20.c */
  1389.    int fnlegal             __(());  /* error if prototyped(?) */ /* tops20.c */
  1390. #endif
  1391.  
  1392. /*---------------------------------------------------------------------------
  1393.     VMS-only functions:
  1394.   ---------------------------------------------------------------------------*/
  1395.  
  1396. #ifdef VMS
  1397.  
  1398. int      check_format      __((void));                              /* vms.c */
  1399. int      find_vms_attrs    __((void));                              /* vms.c */
  1400. int      CloseOutputFile   __((void));                              /* vms.c */
  1401. /* static uch *extract_block  __((struct extra_block *, int *, uch *, int)); */
  1402. /* static int  _flush_blocks  __((int final_flag));                  * vms.c */
  1403. /* static int  _flush_records __((int final_flag));                  * vms.c */
  1404. /* static int  WriteBuffer    __((unsigned char *buf, int len));     * vms.c */
  1405. /* static int  WriteRecord    __((unsigned char *rec, int len));     * vms.c */
  1406. /* static void message        __((int string, char *status));        * vms.c */
  1407. void     return_VMS        __((int zip_error));
  1408.  
  1409. #endif
  1410.  
  1411. /*---------------------------------------------------------------------------
  1412.     Miscellaneous/shared functions:
  1413.   ---------------------------------------------------------------------------*/
  1414.  
  1415. int      match             __((char *s, char *p, int ic));        /* match.c */
  1416. int      iswild            __((char *p));                         /* match.c */
  1417.  
  1418. void     envargs           __((int *, char ***, char *));       /* envargs.c */
  1419. void     mksargs           __((int *, char ***));               /* envargs.c */
  1420.  
  1421. int      dateformat        __((void));
  1422. int      mapattr           __((void));                              /* local */
  1423. int      mapname           __((int renamed));                       /* local */
  1424. int      checkdir          __((char *pathcomp, int flag));          /* local */
  1425. char    *do_wild           __((char *wildzipfn));                   /* local */
  1426. #ifndef MTS /* macro in MTS */
  1427.    void  close_outfile     __((void));                              /* local */
  1428. #endif
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434. /************/
  1435. /*  Macros  */
  1436. /************/
  1437.  
  1438. #ifndef MAX
  1439. #  define MAX(a,b)   ((a) > (b) ? (a) : (b))
  1440. #endif
  1441. #ifndef MIN
  1442. #  define MIN(a,b)   ((a) < (b) ? (a) : (b))
  1443. #endif
  1444.  
  1445. #ifdef DEBUG
  1446. #  define Trace(x)   fprintf x
  1447. #else
  1448. #  define Trace(x)
  1449. #endif
  1450.  
  1451. #if defined(UNIX) || defined(T20_VMS)   /* generally old systems */
  1452. #  define ToLower(x)   ((char)(isupper((int)x)? tolower((int)x) : x))
  1453. #else
  1454. #  define ToLower      tolower          /* assumed "smart"; used in match() */
  1455. #endif
  1456.  
  1457.  
  1458. #define LSEEK(abs_offset) {LONGINT request=(abs_offset)+extra_bytes,\
  1459.    inbuf_offset=request%INBUFSIZ, bufstart=request-inbuf_offset;\
  1460.    if(request<0) {fprintf(stderr, SeekMsg, ReportMsg); return(3);}\
  1461.    else if(bufstart!=cur_zipfile_bufstart)\
  1462.    {cur_zipfile_bufstart=lseek(zipfd,(LONGINT)bufstart,SEEK_SET);\
  1463.    if((incnt=read(zipfd,(char *)inbuf,INBUFSIZ))<=0) return(51);\
  1464.    inptr=inbuf+(int)inbuf_offset; incnt-=(int)inbuf_offset;} else\
  1465.    {incnt+=(inptr-inbuf)-(int)inbuf_offset; inptr=inbuf+(int)inbuf_offset;}}
  1466.  
  1467. /*
  1468.  *  Seek to the block boundary of the block which includes abs_offset,
  1469.  *  then read block into input buffer and set pointers appropriately.
  1470.  *  If block is already in the buffer, just set the pointers.  This macro
  1471.  *  is used by process_end_central_dir (unzip.c) and do_string (file_io.c).
  1472.  *  A slightly modified version is embedded within extract_or_test_files
  1473.  *  (unzip.c).  ReadByte and readbuf (file_io.c) are compatible.
  1474.  *
  1475.  *  macro LSEEK(abs_offset)
  1476.  *      ulg abs_offset;
  1477.  *  {
  1478.  *      LONGINT   request = abs_offset + extra_bytes;
  1479.  *      LONGINT   inbuf_offset = request % INBUFSIZ;
  1480.  *      LONGINT   bufstart = request - inbuf_offset;
  1481.  *
  1482.  *      if (request < 0) {
  1483.  *          fprintf(stderr, SeekMsg, ReportMsg);
  1484.  *          return(3);             /-* 3:  severe error in zipfile *-/
  1485.  *      } else if (bufstart != cur_zipfile_bufstart) {
  1486.  *          cur_zipfile_bufstart = lseek(zipfd, (LONGINT)bufstart, SEEK_SET);
  1487.  *          if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0)
  1488.  *              return(51);        /-* 51:  unexpected EOF *-/
  1489.  *          inptr = inbuf + (int)inbuf_offset;
  1490.  *          incnt -= (int)inbuf_offset;
  1491.  *      } else {
  1492.  *          incnt += (inptr-inbuf) - (int)inbuf_offset;
  1493.  *          inptr = inbuf + (int)inbuf_offset;
  1494.  *      }
  1495.  *  }
  1496.  *
  1497.  */
  1498.  
  1499.  
  1500. #define SKIP_(length) if(length&&((error=do_string(length,SKIP))!=0))\
  1501.   {error_in_archive=error; if(error>1) return error;}
  1502.  
  1503. /*
  1504.  *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
  1505.  *  and unzip.c in several functions.
  1506.  *
  1507.  *  macro SKIP_(length)
  1508.  *      ush length;
  1509.  *  {
  1510.  *      if (length && ((error = do_string(length, SKIP)) != 0)) {
  1511.  *          error_in_archive = error;   /-* might be warning *-/
  1512.  *          if (error > 1)              /-* fatal *-/
  1513.  *              return (error);
  1514.  *      }
  1515.  *  }
  1516.  *
  1517.  */
  1518.  
  1519.  
  1520. #ifdef FUNZIP
  1521. #  define FLUSH    flush
  1522. #  define NEXTBYTE getc(in)   /* redefined in crypt.h if full version */
  1523. #else
  1524. #  define FLUSH(w) if (mem_mode) outcnt=(w); else flush(slide,(ulg)w,0)
  1525. #  define NEXTBYTE (csize-- <= 0 ? EOF : (--incnt >= 0 ? *inptr++ : readbyte()))
  1526. #endif
  1527.  
  1528.  
  1529. #define READBITS(nbits,zdest) {if(nbits>bits_left) {int temp; zipeof=1;\
  1530.   while (bits_left<=8*(sizeof(bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
  1531.   bitbuf|=(ulg)temp<<bits_left; bits_left+=8; zipeof=0;}}\
  1532.   zdest=(int)((ush)bitbuf&mask_bits[nbits]);bitbuf>>=nbits;bits_left-=nbits;}
  1533.  
  1534. /*
  1535.  * macro READBITS(nbits,zdest)    * only used by unreduce and unshrink *
  1536.  *  {
  1537.  *      if (nbits > bits_left) {  * fill bitbuf, which is 8*sizeof(ulg) bits *
  1538.  *          int temp;
  1539.  *
  1540.  *          zipeof = 1;
  1541.  *          while (bits_left <= 8*(sizeof(bitbuf)-1) &&
  1542.  *                 (temp = NEXTBYTE) != EOF) {
  1543.  *              bitbuf |= (ulg)temp << bits_left;
  1544.  *              bits_left += 8;
  1545.  *              zipeof = 0;
  1546.  *          }
  1547.  *      }
  1548.  *      zdest = (int)((ush)bitbuf & mask_bits[nbits]);
  1549.  *      bitbuf >>= nbits;
  1550.  *      bits_left -= nbits;
  1551.  *  }
  1552.  *
  1553.  */
  1554.  
  1555.  
  1556. /*
  1557.  *  Remove all the ASCII carriage returns from buffer buf (length len),
  1558.  *  shortening as necessary (note that len gets modified in the process,
  1559.  *  so it CANNOT be an expression).  This macro is intended to be used
  1560.  *  *before* A_TO_N(); hence the check for CR instead of '\r'.  NOTE:  The
  1561.  *  if-test gets performed one time too many, but it doesn't matter.
  1562.  */
  1563. #define NUKE_CRs(buf,len) \
  1564. { \
  1565.     register int i, j; \
  1566.     for (i = j = 0;  j < len;  (buf)[i++] = (buf)[j++]) \
  1567.         if ((buf)[j] == CR) \
  1568.             ++j; \
  1569.     len = i; \
  1570. }
  1571.  
  1572.  
  1573. /* GRR:  should change name to STRLOWER and use StringLower if possible */
  1574.  
  1575. /*
  1576.  *  Copy the zero-terminated string in str1 into str2, converting any
  1577.  *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  1578.  *  as well, of course.  str1 and str2 may be the same character array.
  1579.  */
  1580. #ifdef __human68k__
  1581. #  define TOLOWER(str1, str2) \
  1582.    { \
  1583.        char *p=(str1), *q=(str2); \
  1584.        uch c; \
  1585.        while ((c = *p++) != '\0') { \
  1586.            if (iskanji(c)) { \
  1587.                if (*p == '\0') \
  1588.                    break; \
  1589.                *q++ = c; \
  1590.                *q++ = *p++; \
  1591.            } else \
  1592.                *q++ = isupper(c) ? tolower(c) : c; \
  1593.        } \
  1594.        *q = '\0'; \
  1595.    }
  1596. #else
  1597. #  define TOLOWER(str1, str2) \
  1598.    { \
  1599.        char  *p, *q; \
  1600.        p = (str1) - 1; \
  1601.        q = (str2); \
  1602.        while (*++p) \
  1603.            *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
  1604.        *q = '\0'; \
  1605.    }
  1606. #endif
  1607. /*
  1608.  *  NOTES:  This macro makes no assumptions about the characteristics of
  1609.  *    the tolower() function or macro (beyond its existence), nor does it
  1610.  *    make assumptions about the structure of the character set (i.e., it
  1611.  *    should work on EBCDIC machines, too).  The fact that either or both
  1612.  *    of isupper() and tolower() may be macros has been taken into account;
  1613.  *    watch out for "side effects" (in the C sense) when modifying this
  1614.  *    macro.
  1615.  */
  1616.  
  1617.  
  1618. #ifndef native
  1619. #  define native(c)   (c)
  1620. #  define A_TO_N(str1)
  1621. #else
  1622. #  ifndef NATIVE
  1623. #    define NATIVE     "native chars"
  1624. #  endif
  1625. #  define A_TO_N(str1) {register unsigned char *p;\
  1626.      for (p=str1; *p; p++) *p=native(*p);}
  1627. #endif
  1628.  
  1629. /*
  1630.  *  Translate the zero-terminated string in str1 from ASCII to the native
  1631.  *  character set. The translation is performed in-place and uses the
  1632.  *  "native" macro to translate each character.
  1633.  *
  1634.  *  macro A_TO_N( str1 )
  1635.  *  {
  1636.  *      register unsigned char *p;
  1637.  *
  1638.  *      for (p = str1;  *p;  ++p)
  1639.  *          *p = native(*p);
  1640.  *  }
  1641.  *
  1642.  *  NOTE:  Using the "native" macro means that is it the only part of unzip
  1643.  *    which knows which translation table (if any) is actually in use to
  1644.  *    produce the native character set.  This makes adding new character set
  1645.  *    translation tables easy, insofar as all that is needed is an appropriate
  1646.  *    "native" macro definition and the translation table itself.  Currently,
  1647.  *    the only non-ASCII native character set implemented is EBCDIC, but this
  1648.  *    may not always be so.
  1649.  */
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655. /*************/
  1656. /*  Globals  */
  1657. /*************/
  1658.  
  1659.    extern int       zipinfo_mode;
  1660.    extern int       aflag;
  1661.    extern int       cflag;
  1662.    extern int       fflag;
  1663.    extern int       hflag;
  1664.    extern int       jflag;
  1665.    extern int       lflag;
  1666.    extern int       overwrite_none;
  1667.    extern int       overwrite_all;
  1668.    extern int       force_flag;
  1669.    extern int       qflag;
  1670. #ifdef DOS_NT_OS2
  1671.    extern int       sflag;
  1672.    extern int       volflag;
  1673. #endif
  1674.    extern int       tflag;
  1675.    extern int       U_flag;
  1676.    extern int       uflag;
  1677.    extern int       V_flag;
  1678.    extern int       vflag;
  1679. #ifdef VMS
  1680.    extern int       secinf;
  1681. #endif
  1682.    extern int       zflag;
  1683. #ifdef MACOS
  1684.    extern int       HFSFlag;
  1685. #endif
  1686.    extern int       filespecs;
  1687.    extern int       xfilespecs;
  1688.    extern int       process_all_files;
  1689.    extern int       create_dirs;
  1690.    extern LONGINT   real_ecrec_offset;
  1691.    extern LONGINT   expect_ecrec_offset;
  1692.    extern long      csize;
  1693.    extern long      ucsize;
  1694.    extern long      used_csize;
  1695.    extern char      **pfnames;
  1696.    extern char      **pxnames;
  1697.    extern char near sig[];
  1698.    extern char near answerbuf[];
  1699.    extern min_info  *pInfo;
  1700.  
  1701.    extern union work area;
  1702.  
  1703.    extern ulg near  crc_32_tab[];
  1704.    extern ulg       crc32val;
  1705.    extern ush near  mask_bits[];
  1706.  
  1707.    extern uch       *inbuf;
  1708.    extern uch       *inptr;
  1709.    extern int       incnt;
  1710.    extern ulg       bitbuf;
  1711.    extern int       bits_left;
  1712.    extern boolean   zipeof;
  1713.    extern char      *zipfn;
  1714.    extern int       zipfd;
  1715.    extern LONGINT   ziplen;
  1716.    extern LONGINT   cur_zipfile_bufstart;
  1717.    extern LONGINT   extra_bytes;
  1718.    extern uch       *extra_field;
  1719.    extern uch       *hold;
  1720.    extern char near local_hdr_sig[];
  1721.    extern char near central_hdr_sig[];
  1722.    extern char near end_central_sig[];
  1723.    extern local_file_hdr  lrec;
  1724.    extern cdir_file_hdr   crec;
  1725.    extern ecdir_rec       ecrec;
  1726.    extern struct stat     statbuf;
  1727.  
  1728.    extern int       mem_mode;
  1729.    extern int       disk_full;
  1730.    extern int       newfile;
  1731. #ifdef SYMLINKS
  1732.    extern int       symlnk;
  1733. #endif
  1734. #ifdef FUNZIP
  1735.    extern FILE      *in;
  1736. #endif
  1737.    extern FILE      *outfile;
  1738.    extern uch       *outbuf;
  1739.    extern uch       *outbuf2;
  1740.    extern uch       *outptr;
  1741.    extern ulg       outcnt;
  1742. #ifdef MSWIN
  1743.    extern char      *filename;
  1744. #else
  1745.    extern char near filename[];
  1746. #endif
  1747.  
  1748.    extern char      *EndSigMsg;
  1749.    extern char      *CentSigMsg;
  1750.    extern char      *SeekMsg;
  1751.    extern char      *ReportMsg;
  1752.  
  1753. #ifdef DECLARE_ERRNO
  1754.    extern int       errno;
  1755. #endif
  1756.  
  1757. #ifdef EBCDIC
  1758.    extern uch       ebcdic[];
  1759. #endif
  1760.  
  1761. #ifdef MACOS
  1762.    extern short     gnVRefNum;
  1763.    extern long      glDirID;
  1764.    extern OSType    gostCreator;
  1765.    extern OSType    gostType;
  1766.    extern boolean   fMacZipped;
  1767.    extern boolean   macflag;
  1768.    extern short     giCursor;
  1769.    extern CursHandle rghCursor[];
  1770. #endif
  1771.  
  1772. #endif /* !__unzip_h */
  1773.